/*
 * @Author: boyyang
 * @Date: 2022-01-11 17:49:40
 * @LastEditTime: 2022-02-21 16:07:55
 * @LastEditors: boyyang
 * @Description: 获取本地图片文件预览
 * @FilePath: \boyyang\plugin\utils\getFileBlob.ts
 */


const getFileBlob = (file: File): string => {
    let url: string = ''
    if (window.URL != undefined) {
        // mozilla(firefox)
        url = window.URL.createObjectURL(file)
    } else if (window.webkitURL != undefined) {
        // webkit or chrome
        url = window.webkitURL.createObjectURL(file)
    } else if (window.FileReader) {
        let reader = new FileReader()
        if (file && file.type.match('image.*')) {
            reader.readAsDataURL(file)
            reader.onloadend = function (e) {
                url = reader.result as string
            }
        }
    }
    return url
}

export {
    getFileBlob
}